

# 执行多条SQL
# 1. 导包
import pymysql
import random
from package_pymysql.utils import random_string
# 2. 建立数据库连接

conn = pymysql.connect(host="localhost",user="root",password="root",database="school",charset="utf8")
print(conn)

# 3. 创建游标
cursor = conn.cursor()

# 4. 执行SQL语句
sql = "insert into students(name,age,sex,class,card,city) values(%s,%s,%s,%s,%s,%s)"

number = 10

for index in range(number):
    lst = []
    lst.append(random_string(6))
    lst.append(random.randint(20, 40))
    lst.append(random.choice(('男', '女')))
    lst.append(random.choice(('1班', '2班', '3班', '4班')))
    lst.append(random.randint(10000000, 999999999999))
    lst.append(random.choice(('北京', '上海', '广州', '深圳', '天津')))
    cursor.execute(sql,args=lst)



# 5. 关闭游标
cursor.close()

# 6. 关闭链接
conn.close()